<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>内部通讯列表</title>
    <link href="<%=path%>/css/core.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/pagination.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/list.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/xToolbar.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/jquery-impromptu.css" rel="stylesheet" type="text/css"/>
  </head>
  <body>
    <div id="toolbar"></div>
    <form id="listForm" action="<%=path%>/system/intercom/listPagination.t4m" method="post">
      <s:hidden name="searchType"/>
      <div class="search-div">
        <div class="search-condition">
          <table class="search-table" cellspacing="0" cellpadding="0">
            <tr>
              <td class="c-left">标题：</td>
              <td colspan="3"><input name="searchValue" type="text" class="text" value="<s:property value="searchValue[0]"/>"/></td>
            </tr>
            <tr>
              <td class="c-left">发送时间：</td>
              <td><input name="searchValue" id="minD" type="text" class="text Wdate" value="<s:property value="searchValue[1]"/>" onclick="WdatePicker({maxDate:'#F{$dp.$D(\'maxD\')}'});"/></td>
              <td class="c-left">到：</td>
              <td><input name="searchValue" id="maxD" type="text" class="text Wdate" value="<s:property value="searchValue[2]"/>" onclick="WdatePicker({minDate:'#F{$dp.$D(\'minD\')}'});"/></td>
            </tr>
          </table>
        </div>
        <div class="search-commit">
          <a href="javascript:void(0)" class="search-button" onclick="$('#searchType').val('and');$('#listForm').submit();">与查询</a>
          <a href="javascript:void(0)" class="search-button" onclick="$('#searchType').val('or');$('#listForm').submit();">或查询</a>
        </div>
      </div>
      <table id="titleTable" cellpadding="0" cellspacing="0">
        <tr>
          <td>&nbsp;</td>
          <td><input type="checkbox" id="allBox"/></td>
          <td id="titleSort">标题</td>
          <td>发送人</td>
          <td id="timeSort">发送时间</td>
          <td>状态</td>
        </tr>
      </table>
      <table id="dataTable" cellpadding="0" cellspacing="0">
        <s:iterator id="intercom" value="page.list" status="i">
          <tr class="row">
            <td class="num"><s:property value="#i.index+1"/></td>
            <td class="box"><input type="checkbox" name="idList" value="<s:property value="#intercom.id"/>"/></td>
            <td><span><s:property value="#intercom.title"/></span></td>
            <td align="center"><span><s:property value="#intercom.sender.realName"/></span></td>
            <td align="center"><span><s:date name="#intercom.sendTime" format="yyyy-MM-dd HH:mm"/></span></td>
            <td align="center"><span id="read_<s:property value="#intercom.id"/>"><s:property value="@org.team4.constants.StringConstant@INTERCOM_SELECT.get(#intercom.readFlag)" escape="false"/>&nbsp;</span></td>
          </tr>
        </s:iterator>
      </table>
      <s:hidden name="type"/>
      <s:include value="/share/pagebar.jsp"/>
    </form>
    
    <script src="<%=path%>/js/core.js" type="text/javascript"></script>
    <script src="<%=path%>/js/share.js" type="text/javascript"></script>
    <script src="<%=path%>/js/jquery.js" type="text/javascript"></script>
    <script src="<%=path%>/js/Grid.js" type="text/javascript"></script>
    <script src="<%=path%>/js/BoxSelect.js" type="text/javascript"></script>
    <script src="<%=path%>/js/xToolbar.js" type="text/javascript"></script>
    <script src="<%=path%>/js/xToolbar.items.js" type="text/javascript"></script>
    <script src="<%=path%>/js/jquery-impromptu.js" type="text/javascript"></script>
    <script src="<%=path%>/js/datePicker/WdatePicker.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function(){

      var toolbar = new Toolbar({
        id: '1',
        renderTo : 'toolbar',
        icon: '../../image/op.gif',
        items : [{
          type : 'button',
          text : '新建',
          useable : '<s:property value="@org.team4.util.Meta@getOperate(\"intercom_new\")"/>',
          position: {
            a: '-180px -40px',
            b: '-180px -160px'
          },
          handler : function(){
            top.intercomFunctions.openSaveIntercomWindow('');
          }
        },{
          type : 'button',
          text : '转发',
          useable : '<s:property value="@org.team4.util.Meta@getOperate(\"intercom_forward\")"/>',
          position: {
            a: '-180px -20px',
            b: '-180px -140px'
          },
          handler : function(){
            if(getFirstID())
              top.intercomFunctions.openSaveIntercomWindow(getFirstID());
          }
        },{
          type : 'button',
          text : '删除',
          useable : '<s:property value="@org.team4.util.Meta@getOperate(\"intercom_delete\")"/>',
          position: {
            a: '-180px 0px',
            b: '-180px -120px'
          },
          handler : function(){
            del({
              deleteURL : '<%=path%>/system/intercom/delete.t4m'
            });
          }
        },'-',{
          type : 'button',
          text : '查看',
          useable : '<s:property value="@org.team4.util.Meta@getOperate(\"intercom_view\")"/>',
          position: {
            a: '-180px -60px',
            b: '-180px -180px'
          },
          handler : function(){
            if(getFirstID()) {
              var i_id = getFirstID();
              //将未读标记为已读
              $.ajax({
                async : false,
                url : '<%=path%>/system/ajax/updateIntercomToRead.t4m',
                data : 'intercomId='+i_id,
                success : function(json){
                  $('#read_'+i_id).html(json);
                }
              });
              viewIntercom(i_id, '<s:property value="@org.team4.util.Meta@getOperate(\"intercom_forward\")"/>');
            }
          }
        },'-',{
          type: 'search'
        },{
          type: 'filters',
          active: '<s:property value="type"/>',
          items: [{
            id : 'ALL',
            tip : '全部',
            position: {
              a: '-20px -80px'/*,
              b: '-20px -200px'*/
            },
            handler : function(){
              filterIntercom('ALL');
            }
          },{
            id : 'F',
            tip : '未读',
            position: {
              a: '0px -80px'/*,
              b: '0px -200px'*/
            },
            handler : function(){
              filterIntercom('F');
            }
          },{
            id : 'T',
            tip : '已读',
            position: {
              a: '-40px -80px'/*,
              b: '-40px -200px'*/
            },
            handler : function(){
              filterIntercom('T');
            }
          },{
            id : 'S',
            tip : '已发送',
            position: {
              a: '-60px -80px'/*,
              b: '-60px -200px'*/
            },
            handler : function(){
              filterIntercom('S');
            }
          }]
        }]
      });
      
      new Grid({
        titleTable:'titleTable',
        dataTable:'dataTable',
        widths : [26,24,250,80,130,60],
        height : function(){return getGridHeight({toolbarId:'toolbar',hasPage:true});},
        dbView : function(id){
          //将未读标记为已读
          $.ajax({
            async : false,
            url : '<%=path%>/system/ajax/updateIntercomToRead.t4m',
            data : 'intercomId='+id,
            success : function(json){
              $('#read_'+id).html(json);
            }
          });
          viewIntercom(id, '<s:property value="@org.team4.util.Meta@getOperate(\"intercom_forward\")"/>');
        }
      });
      
      new BoxSelect({
        allId : 'allBox',
        boxName : 'idList'
      });
      
      loadReady();
    });
    
    function filterIntercom(type) {
      window.location = '<%=path%>/system/intercom/listPagination.t4m?type='+type;
    }
    
    function updateReadFlag() {
      if(getFirstID()){
        document.getElementById('listForm').action = '<%=path%>/system/intercom/updateReadFlag.t4m';
        document.getElementById('listForm').submit();
      }
    }
    
    function updateAllReadFlag() {
      document.getElementById('listForm').action = '<%=path%>/system/intercom/updateAllReadFlag.t4m';
      document.getElementById('listForm').submit();
    }
    
    function viewIntercom(intercomId, forwardable) {
      top.intercomFunctions.openViewIntercomWindow(intercomId, forwardable);
    }
    </script>
  </body>
</html>